<html>
<head><meta charset="utf-8"><title>uninhabitedness check · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html">uninhabitedness check</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193933692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193933692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193933692">(Apr 14 2020 at 17:49)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="245339">@Nadrieril</span> <span class="user-mention" data-user-id="126931">@centril</span> </p>
<p>So I'm creating this to followup on <a href="https://github.com/rust-lang/rust/pull/71074#issuecomment-613423782" title="https://github.com/rust-lang/rust/pull/71074#issuecomment-613423782">https://github.com/rust-lang/rust/pull/71074#issuecomment-613423782</a></p>



<a name="193933828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193933828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193933828">(Apr 14 2020 at 17:50)</a>:</h4>
<blockquote>
<p>That's what I have so far: <a href="https://github.com/rust-lang/rust/compare/master...Nadrieril:exhaustiveness-remove-tyerr" title="https://github.com/rust-lang/rust/compare/master...Nadrieril:exhaustiveness-remove-tyerr">master...Nadrieril:exhaustiveness-remove-tyerr</a>. I've reduced the problem to a simpler case: now we only use tyerr in the case where a struct has private empty fields, because we don't want users outside the crate to know that the struct is uninhabited. (There's also something about non_exhaustive, but same thing here). The fix looks super easy: simply skip over those fields as if they never existed. But in practice there are so many places in the code where that would matter and I see no clean way of making sure that I get it right and that people in the future will get it right too &gt;&lt;. It's all the places where one of ty::Adt, Constructor::Variant/Simple or PatKind::Variant/Leaf appear, essentially. If anyone has an idea of how to get that right, I'm feeling stuck right now.</p>
</blockquote>



<a name="193933891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193933891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193933891">(Apr 14 2020 at 17:50)</a>:</h4>
<p>does it make sense to wrap those structs with some other struct that forces you to decide whether to see fields or not?</p>



<a name="193934422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193934422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193934422">(Apr 14 2020 at 17:54)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="121053">@varkor</span></p>



<a name="193935150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193935150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193935150">(Apr 14 2020 at 18:00)</a>:</h4>
<p>To illustrate, on this line: <a href="https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L2372" title="https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L2372">https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L2372</a> we have as input a pattern like <code>SomeStruct { field2: Some(42), .. }</code> and we need to essentially expand that into <code>{ field1: _, field2: Some(42) }</code> while making sure to not include uninhabited private fields</p>



<a name="193935383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193935383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193935383">(Apr 14 2020 at 18:02)</a>:</h4>
<p>Or here <a href="https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L1002" title="https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L1002">https://github.com/rust-lang/rust/blob/6805906fba0bca2bc77da9ad09cc9f91c3cea3eb/src/librustc_mir_build/hair/pattern/_match.rs#L1002</a> we have to do the reverse: given a filtered list of patterns, we need to reconstruct a full <code>PatKind</code> by filling in the holes with wildcards of the correct type</p>



<a name="193951968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193951968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193951968">(Apr 14 2020 at 20:20)</a>:</h4>
<p>So I'm not sure what we'd have to wrap. Probably Pat ? But that would touch every single bit of the code. Maybe changing PatKind a bit could be enough, I don't know what else it's used for</p>



<a name="193966825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193966825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193966825">(Apr 14 2020 at 22:53)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> So one question is: is this something all of those pieces of code should care about? if so, then maybe it actually makes sense to go change all of those lines of code.</p>



<a name="193967564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193967564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193967564">(Apr 14 2020 at 23:04)</a>:</h4>
<p>I don't really know how to answer that honestly. Changing all those lines, sure, but how to be sure we didn't miss any ?</p>



<a name="193967731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193967731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193967731">(Apr 14 2020 at 23:07)</a>:</h4>
<p>Actually, maybe PatKind::Variant could take some custom <code>Fields</code> struct instead of a Vec&lt;Pat&gt;...</p>



<a name="193967814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/193967814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#193967814">(Apr 14 2020 at 23:08)</a>:</h4>
<p>What else is Pat used for ? The scope of mir::hair::pattern looks rather limited so I might be able to change it</p>



<a name="194318313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194318313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194318313">(Apr 16 2020 at 15:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/131828-t-compiler/topic/uninhabitedness.20check/near/193967564" title="#narrow/stream/131828-t-compiler/topic/uninhabitedness.20check/near/193967564">said</a>:</p>
<blockquote>
<p>I don't really know how to answer that honestly. Changing all those lines, sure, but how to be sure we didn't miss any ?</p>
</blockquote>
<p>Right, that's why I suggested changing the struct itself... it wouldn't compile until we had fixed all the places it's used... that said, I'm mostly speaking abstractly without much concrete knowledge beyond the examples you gave</p>



<a name="194610915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194610915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194610915">(Apr 19 2020 at 18:15)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Originally on the PR thread, <span class="user-mention" data-user-id="119009">@eddyb</span> had suggested adding a field to <code>Pat</code> with the extra information. Does this end up having the same problem that we need to remember to check it?</p>



<a name="194610969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194610969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194610969">(Apr 19 2020 at 18:16)</a>:</h4>
<p><em>not</em> <code>struct Pat</code></p>



<a name="194610970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194610970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194610970">(Apr 19 2020 at 18:16)</a>:</h4>
<p>but the <code>Wild</code> variant of <code>enum PatKind</code></p>



<a name="194610975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194610975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194610975">(Apr 19 2020 at 18:16)</a>:</h4>
<p>(or maybe even another variant, depending)</p>



<a name="194611265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194611265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194611265">(Apr 19 2020 at 18:23)</a>:</h4>
<p>I think the relevant info needs to live rather on the side where _match acts, not in Pat, so I was thinking of making ctor_wild_subpatterns be a special struct Fields rather than just a slice</p>



<a name="194621686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194621686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194621686">(Apr 19 2020 at 22:52)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Do you mean something like this:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Fields</span><span class="o">&lt;</span><span class="na">&#39;p</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">fields</span>: <span class="kp">&amp;</span><span class="na">&#39;p</span><span class="w"> </span><span class="p">[</span><span class="n">Pat</span><span class="o">&lt;</span><span class="na">&#39;tcx</span><span class="o">&gt;</span><span class="p">],</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="na">&#39;p</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Fields</span><span class="o">&lt;</span><span class="na">&#39;p</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Returns an iterator over all fields.</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">iter_all</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="n">Pat</span><span class="o">&lt;</span><span class="na">&#39;tcx</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">fields</span><span class="p">.</span><span class="n">iter</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="sd">/// Returns an iterator that hides uninhabitedness.</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">iter_habited</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="n">Pat</span><span class="o">&lt;</span><span class="na">&#39;tcx</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">fields</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">pat</span><span class="o">|</span><span class="w"> </span><span class="n">todo</span><span class="o">!</span><span class="p">())</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="194621695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194621695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194621695">(Apr 19 2020 at 22:53)</a>:</h4>
<p>And then force all users to pick one?</p>



<a name="194622253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194622253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194622253">(Apr 19 2020 at 23:06)</a>:</h4>
<p>Yeah something like that, but more principled so that users know when to use which</p>



<a name="194622304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194622304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194622304">(Apr 19 2020 at 23:08)</a>:</h4>
<p>I mean we'd find names for those methods that make it clearer what's happening</p>



<a name="194622319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194622319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194622319">(Apr 19 2020 at 23:09)</a>:</h4>
<p>Actually it's the reverse we want: store only the filtered list but have methods to reconstruct the full one. We need that because on Constructor::apply we only get back the filtered list</p>



<a name="194622379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194622379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194622379">(Apr 19 2020 at 23:11)</a>:</h4>
<p>Essentially there's a neat underlying idea to the whole file: you can split a value into a Constructor applied to some Fields. Right now we've provided Constructor and it's neat, but the other half is handled way more ad-hoc. Having Fields would fill that gap, and we'd be able to hide stuff like field filtering under that abstraction layer I hope</p>



<a name="194622385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/194622385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#194622385">(Apr 19 2020 at 23:11)</a>:</h4>
<p>I need to stare at the code some more though, all this is just off the top of my head</p>



<a name="195118849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/195118849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#195118849">(Apr 23 2020 at 20:59)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Hmm, I think I vaguely understand, though you might have to explain some of that to me a bit more. Is there anything I can help with?</p>



<a name="195125929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/195125929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#195125929">(Apr 23 2020 at 22:13)</a>:</h4>
<p>Thanks, I appreciate the offer :) I'm not really clear myself on what needs to be done though. I haven't had time to invest in this sadly, but when I do I'll be sure to let you know!</p>



<a name="196004256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196004256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196004256">(May 01 2020 at 20:11)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Do you mind if I take a stab at this? I would like to try to make progress on <a href="https://github.com/rust-lang/rust/pull/70551" title="https://github.com/rust-lang/rust/pull/70551">https://github.com/rust-lang/rust/pull/70551</a> which is blocked on de-abusing <code>TyKind::Error</code>... Do you mind if I ask you some questions?</p>



<a name="196004627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196004627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196004627">(May 01 2020 at 20:14)</a>:</h4>
<p>Sure, ask away :) I'll try to not take too long to answer</p>



<a name="196005500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196005500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196005500">(May 01 2020 at 20:23)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="245339">@Nadrieril</span>! Any suggestions for a starting point? So far I've define a <code>Fields</code> struct as above (but I will change it as you described). IIUC, I should change <code>Constructor::apply</code> to use <code>Fields</code> instead of <code>Iterator&lt;Pat&gt;</code>, and it should use the filtered list correct? Also can you point me to an example of constructing the full list so I can see how to do that?</p>



<a name="196013712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196013712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196013712">(May 01 2020 at 21:44)</a>:</h4>
<p>Oh, one other thing: as I've been looking at the code, I've found that sometimes we have owned <code>Pat</code>s and sometimes we have references/slices of <code>Pat</code>s on an arena... would it be possible to _always_ intern <code>Pat</code> in the arena and only deal with a thin handle (kind of like we do with <code>ty::Ty</code>?</p>



<a name="196015806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196015806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196015806">(May 01 2020 at 22:09)</a>:</h4>
<p>Looking a bit more, it looks like only the match-checking code uses an arena... would it be possible to convert the other uses of <code>Pat</code> to also use (a different) arena? We could also make <code>PatKind</code> be arena-allocated. Currently, we are using boxes...</p>



<a name="196024960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196024960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196024960">(May 02 2020 at 00:51)</a>:</h4>
<p><span class="user-mention" data-user-id="198054">@mark-i-m</span>  About arenas, I honestly don't know. I'm guessing there aren't many places where we have a choice because any Pat we want to store in the matrix need to be  arena-allocated. So anything in Fields will have to be in the arena for example. Would it simplify things if everything was in the arena ?</p>



<a name="196025098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025098">(May 02 2020 at 00:54)</a>:</h4>
<p>Indeed Constructor::apply would take Fields as input. And wildcard_subpatterns would return Fields. Constructor::arity would need to be updated to take into account that we filtered some fields out</p>



<a name="196025121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025121">(May 02 2020 at 00:54)</a>:</h4>
<p>I mean, start of course by just using Field in the right places and not filter out anything. We can add filtering later once we're sure everything still works</p>



<a name="196025131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025131">(May 02 2020 at 00:55)</a>:</h4>
<p>Honestly I hope that's the right approach, I'm far from certain</p>



<a name="196025211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025211">(May 02 2020 at 00:57)</a>:</h4>
<p>One of the trickiest bits I expected to be <code>patterns_for_variant</code>. That may force Fields to be a Vec&lt;&amp;'p Pat&gt; instead of a slice. Or a Cow maybe</p>



<a name="196025324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025324">(May 02 2020 at 01:00)</a>:</h4>
<p>Ah and I expect specialize_one_pattern to return Fields of course</p>



<a name="196025330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025330">(May 02 2020 at 01:01)</a>:</h4>
<p>That's kind of the inverse of apply</p>



<a name="196025455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196025455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196025455">(May 02 2020 at 01:04)</a>:</h4>
<p>Ugh the comment there is a bit confused. I'm starting to think you might need to understand the actual algorithm to make this work &gt;&lt;</p>



<a name="196027134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196027134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196027134">(May 02 2020 at 01:52)</a>:</h4>
<p>I _think_ I've mentioned most of the functions that would need a change ? So maybe it's not that complicated</p>



<a name="196063189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196063189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196063189">(May 02 2020 at 18:02)</a>:</h4>
<p><span class="user-mention" data-user-id="198054">@mark-i-m</span>  I should finally be free of stress on Tuesday. I had planned to work on this then, so if you prefer I'm happy to do it then, and then your PR can move forward</p>



<a name="196063801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196063801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196063801">(May 02 2020 at 18:19)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Thanks for the comments! I probably won't get to work a lot on this before Tuesday, so it might make more sense for you to go ahead. It would probably take me a while because I would need to go through and understand the code first. Still, I'm glad to help in any way I can.</p>



<a name="196369791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196369791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196369791">(May 05 2020 at 21:20)</a>:</h4>
<p><span class="user-mention" data-user-id="198054">@mark-i-m</span> <a href="https://github.com/rust-lang/rust/pull/71930" title="https://github.com/rust-lang/rust/pull/71930">https://github.com/rust-lang/rust/pull/71930</a></p>



<a name="196491265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/196491265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#196491265">(May 06 2020 at 04:28)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="245339">@Nadrieril</span>!</p>



<a name="197573017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/197573017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#197573017">(May 14 2020 at 15:33)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> Btw, if you have time, would you be interested in writing up some documentation about pattern checking the rustc-dev-guide? <a href="https://rustc-dev-guide.rust-lang.org/pat-exhaustive-checking.html">https://rustc-dev-guide.rust-lang.org/pat-exhaustive-checking.html</a></p>



<a name="197608146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/197608146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#197608146">(May 14 2020 at 19:46)</a>:</h4>
<p>It's been on my todo list for a while yeah x)</p>



<a name="197608235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/197608235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#197608235">(May 14 2020 at 19:47)</a>:</h4>
<p>I'll try when I find some time</p>



<a name="197623044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/uninhabitedness%20check/near/197623044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/uninhabitedness.20check.html#197623044">(May 14 2020 at 21:51)</a>:</h4>
<p>I'll try when I find some time</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>